// CSC 234 01TR WalstonW

#include "include.h"

Mothma::Mothma(int xPosition, int yPosition, int xResolution, int yResolution)
{   
    this->xPosition = xPosition;
    this->yPosition = yPosition;
    this->xResolution = xResolution;
    this->yResolution = yResolution; 
    this->start_frame = 0;
    this->end_frame = 0;
    
    // Mothma-specific variable can be tweaked here
    // so when she loads in the game, she's ready to go
    
    current_run_speed = 0;
    accel_rate = 1;
    max_run_speed =5;
    
    hitPoints = MAX_HP;
    current_frame = 0;
    jump_distance = 0;
    jump_rate = 1;
    jumping = false;
    falling = false;
    current_state = "stand";
    this->addFrames(1,"img/mothma/stand/mothma_stand.png",0, P1_W, P1_H);
    this->addFrames(1,"img/mothma/walk/mothma_walk_1.png",0, 230, P1_H);
    this->addFrames(1,"img/mothma/walk/mothma_walk_2.png",0, 230, P1_H);
    this->addFrames(1,"img/mothma/walk/mothma_walk_3.png",0, 230, P1_H);
    this->addFrames(1,"img/mothma/death/mothma_death1.png",0, 512, 512);
    this->addFrames(1,"img/mothma/death/mothma_death2.png",0, 512, 512);
    this->addFrames(1,"img/mothma/death/mothma_death3.png",0, 512, 512);
    this->addFrames(1,"img/mothma/death/mothma_death4.png",0, 512, 512);
    this->addFrames(1,"img/mothma/death/mothma_death5.png",0, 512, 512);
    this->addFrames(1,"img/mothma/death/mothma_death6.png",0, 512, 512);
    this->addFrames(1,"img/mothma/death/mothma_death7.png",0, 512, 512);
    this->addFrames(1,"img/mothma/block/mothma_block.png",0, P1_W, P1_H);
    this->addFrames(1,"img/mothma/attack/mothma_attack_1.png",0, 312, 430);
    this->addFrames(1,"img/mothma/attack/mothma_attack_2.png",0, 312, 430);
    this->addFrames(1,"img/mothma/attack/mothma_attack_3.png",0, 312, 430);
}

void Mothma::animate()
{
   if (!falling && jumping && jump_distance < 200){
     this->yPosition -= jump_rate;
     jump_rate += jump_rate;
     jump_distance += jump_rate;
   }
   else {
     jumping = false;
     jump_distance = 0;
     jump_rate = 1;   
   }
   if (!jumping && this->yPosition + P1_H < 550 && hitPoints){
     this->yPosition += jump_rate*3;
     jump_rate += jump_rate;
     falling = true;
   }
   else {
     jump_rate = 2;
     falling = false;     
   }
   
   if (current_state == "stand")
   {
     current_frame = 0;
     start_frame = 0;
     end_frame = 0;
     if (current_run_speed < 0)
       current_run_speed -= accel_rate;
     else
       current_run_speed = 0;   
   }
   else if (current_state == "block")
   {
     this->setStartingFrame(11);
     this->setEndingFrame(11);
   }
   else if (current_state == "mov_left")
   {
     start_frame = 1;
     end_frame = 3;
     this->moveObject(-current_run_speed,0);
     if (current_run_speed < max_run_speed)
       current_run_speed += accel_rate;
     /*if (current_frame < 3)
            current_frame++;
     else
            current_frame = 1;*/
   }
   else if(current_state == "mov_right")
   {
     start_frame = 1;
     end_frame = 3;
     this->moveObject(current_run_speed,0);
     if (current_run_speed < max_run_speed)
       current_run_speed += accel_rate;
    /* if (current_frame < 3)
       current_frame++;
     else
       current_frame = 1;*/
   }
   
   if(current_state == "attacking")
   {
     start_frame = 12;
     end_frame = 14;
     /*if (current_frame < 12 || current_frame == 14){  
       current_frame = 12;
     }
     else if (current_frame < 14)
       current_frame++;*/
   }    
       
   if(current_state == "dying")
   {
     if (start_frame != 4 && end_frame != 10)
       this->moveObject(-300,-82);
       
     start_frame = 4;
     end_frame = 10;
       
     /*if (current_frame < 4 || current_frame > 10){
       this->moveObject(-300,-82);
       current_frame = 4;
     }
     else if (current_frame < 10)
       current_frame++; */
     if (current_frame == 10)
       start_frame = 10;
   }            
      
}
